<template>
	<view class="productItem" :class="{'selected': source.selected}">
		<view class="user-info" @click="select">
			<uni-icons v-if="source.selected" type="checkbox-filled" class="icon" size="26" color="#555BFF"></uni-icons>
			<uni-icons v-else type="circle" class="icon" size="26" color="#999999"></uni-icons>
			<view class="name" @click.stop="goProductDetail">
				{{ source.productName }}
			</view>
			<uni-icons type="right" color="#898989" size="18"></uni-icons>
			<!-- <uni-icons type="phone" v-if="source.supplierTel" size="18" color="#666"></uni-icons>
			<view class="tel" @click.stop="callPhone(source.supplierTel)">
				{{ source.supplierTel }}
			</view> -->
		</view>
		<!-- <view class="title-wrapper">
			<view class="title">{{ source.productName }}</view>
			<uni-icons type="right" color="#898989" size="18"></uni-icons>
		</view> -->
		<view class="info-wrapper">
			<view class="info lose">
				<view class="date-wrapper">
					<text class="date" v-if="source.priceUpdateTime">{{ source.priceUpdateTime.substring(5,16) }}</text>
					<text>上报</text>
					<view v-if="source.currentPrice" class="tag">
						历史
					</view>
					<view class="status">{{ source.currentPrice ? "":"已失效" }}</view>
				</view>
				<view class="spec-wrapper">
					<view class="spec">
						<text>价格：</text>
						<text>{{ source.lastExaminePrice || source.sellingPrice }}元/件</text>
					</view>
					<view class="spec">
						<text>供应量：</text>
						<text>{{ source.supply }}件</text>
					</view>
				</view>
				<view class="spec-wrapper">
					<view class="spec">
						<text>净单价：</text>
						<text>{{ source.preUnitPrice }}元/斤</text>
					</view>
					<view class="spec">
						<text>净重：</text>
						<text>{{ source.netWeight }}斤/件</text>
					</view>
				</view>
			</view>
			<view class="info second" v-if="source.currentPrice">
				<view class="date-wrapper">
					<text class="date"
						v-if="source.currentApplyTime">{{ source.currentApplyTime.substring(5,16) }}</text>
					<text>上报</text>
					<view class="tag current">
						当前
					</view>
					<view class="status">待审核</view>
				</view>
				<view class="spec-wrapper">
					<view class="spec">
						<text>价格：</text>
						<text>{{ source.examinePrice || source.currentPrice }}元/件</text>
					</view>
					<view class="spec">
						<text>供应量：</text>
						<text>{{ source.currentSupply }}件</text>
					</view>
				</view>
				<view class="spec-wrapper">
					<view class="spec">
						<text>净单价：</text>
						<text>{{ source.unitPrice }}元/斤</text>
					</view>
					<view class="spec">
						<text>净重：</text>
						<text>{{ source.netWeight }}斤/件</text>
					</view>
				</view>
			</view>

			<view class="info error" v-if="source.warning">
				<view class="spec-wrapper">
					<view class="date">
						<text>警示:当前报价</text>
						<text v-if="source.warningType === 'max'" class="error">高于</text>
						<text v-else class="error">低于</text>
						<text>平台警示价【{{ source.warningText }}元/斤】(净单价)，</text>
						<text>建议将单件价格调整到【{{ source.warningText2 }}元/件】范围内。</text>
					</view>
				</view>
			</view>
		</view>
		<view class="btn-wrapper" v-if="index == 1">
			<view class="btn" @click="changePrice">
				调整价格
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		props: {
			index: {
				type: Number,
				default () {
					return 0
				}
			},
			source: {
				type: Object,
				default () {
					return {}
				}
			}
		},
		data() {
			return {

			}
		},
		mounted() {

		},
		methods: {
			select() {
				this.$emit("select", this.source.id)
			},
			callPhone(tel) {
				uni.makePhoneCall({
					phoneNumber: tel
				})
			},
			changePrice() {
				this.$emit('changePrice', this.source)
			},
			goProductDetail() {
				uni.navigateTo({
					url: '/subPage_product/productDetail?id=' + this.source.id + '&isPrice=true'
				})
			}
		},
		components: {

		}
	}
</script>

<style lang="scss" scoped>
	.productItem {
		background-color: #ffffff;
		border-radius: 25upx;
		overflow: hidden;

		&.selected {
			box-shadow: 0 0 10upx #555BFFAA;
		}

		.user-info {
			display: flex;
			align-items: center;
			font-size: 32upx;
			margin-bottom: 20upx;
			height: 80upx;
			background-color: #F5F6FA;
			padding: 0 20upx;

			.name {
				font-weight: bold;
				flex: 1;
				color: #222222;
				text-overflow: -o-ellipsis-lastline;
				overflow: hidden; //溢出内容隐藏
				text-overflow: ellipsis; //文本溢出部分用省略号表示
				display: -webkit-box; //特别显示模式
				-webkit-line-clamp: 1; //行数
				line-clamp: 1;
				-webkit-box-orient: vertical; //盒子中内容竖直排列
			}

			.tel {
				color: #666;
			}

			.icon {
				margin-right: 5upx;
			}
		}

		.title-wrapper {
			display: flex;
			align-items: center;
			margin-bottom: 10upx;
			padding: 0 24upx;

			.title {
				flex: 1;
				font-size: 32upx;
				font-weight: bold;
				line-height: 36upx;
				margin-bottom: 20upx;
				width: 500rpx;
				text-overflow: -o-ellipsis-lastline;
				overflow: hidden; //溢出内容隐藏
				text-overflow: ellipsis; //文本溢出部分用省略号表示
				display: -webkit-box; //特别显示模式
				-webkit-line-clamp: 2; //行数
				line-clamp: 2;
				-webkit-box-orient: vertical; //盒子中内容竖直排列
				color: #434343;
			}

			.type {
				color: #f90;
				font-size: 32upx;
			}
		}

		.info-wrapper {
			display: flex;
			padding-bottom: 30upx;
			flex-direction: column;

			.info {
				flex: 1;
				padding: 20upx;
				margin: 0 20upx;
				border-radius: 10upx;
				background-color: #555BFF11;

				&.second {
					margin-top: 20upx;
					color: #555BFF;
				}

				&.error {
					margin-top: 20rpx;
					background-color: #ff000022;
					color: #434343;

					.error {
						color: #f00;
						font-weight: bold;
					}
				}

				.date-wrapper {
					display: flex;
					align-items: center;
					justify-content: space-between;
					font-size: 28upx;
					color: #555555;
					line-height: 28upx;
					margin-bottom: 10upx;

					.status {
						flex: 1;
						color: #f90;
						text-align: right;
					}

					.date {
						margin-right: 10upx;
					}

					.tag {
						margin-left: 10upx;
						font-size: 22upx;
						width: 70upx;
						height: 34upx;
						display: flex;
						align-items: center;
						justify-content: center;
						border-radius: 10upx;
						background-color: #808080;
						color: #ffffff;

						&.current {
							background-color: #555BFF;
						}
					}
				}

				.spec-wrapper {
					display: flex;
					align-items: center;
					justify-content: space-between;
					font-size: 28upx;
				}

				&.lose {
					background-color: #f7f7f7;

					.date-wrapper {
						color: #898989;
					}

					.spec-wrapper {
						color: #898989;
					}
				}
			}
		}


		.delivery-quantity {
			display: flex;
			align-items: center;
			padding: 20upx 0;
			margin-top: 20upx;
			border-top: 1upx solid #efefef;

			.item {
				flex: 1;
				font-size: 30upx;

				&.center {
					text-align: center;
				}

				&.right {
					text-align: right;
				}
			}
		}

		.btn-wrapper {
			display: flex;
			align-items: center;
			justify-content: flex-end;
			margin-top: -10rpx;
			padding-right: 20rpx;
			padding-bottom: 20rpx;

			.btn {
				width: 200rpx;
				height: 60rpx;
				display: flex;
				align-items: center;
				justify-content: center;
				background-color: #555BFF11;
				border: 1upx solid #555BFF;
				color: #555BFF;
				border-radius: 10upx;
				font-size: 28upx;
			}
		}
	}
</style>